<?php

class Adept_Component_Button extends Adept_Component_Control 
{

    const CLICK_EVENT = 'click';
    
    protected $clicked = false;
    
    public function processRequest()
    {
        $request = $this->getContext()->getRequest();
        if ($request[$this->getId()] !== null) {
            $this->clicked = true;
            $this->addEventPhase();
        }
        
    }
    
    public function isValid() 
    {
        if (($form = $this->getParentForm()) != null) {
           return $form->isValid();
        }
        return true;    	
    }	
    
    public function processEvent() 
    {
        if ($this->clicked && $this->isValid()) {
            $this->invokeListenersChain(self::CLICK_EVENT, array($this));
        }
    }    
    
    public function addClickListener($listener)
    {
        $this->addListener(self::CLICK_EVENT, $listener);
    }
    
    public function hasRenderer()
    {
        return true;
    } 
    
}